#include<vector>
class MyCircularDeque {
public:
    int l, r, size ,len;
    std::vector<int> linkedList;

    MyCircularDeque(int k) {
        size = k;
        l = r = 0;
        len = 0;
        linkedList.resize(k);
    }

    bool insertFront(int value) {
        if (len == size) 
            return false;
        if (len == 0) {
            linkedList[l] = value;
            len++;
            return true;
        }
        len++;
        if (l == 0)
            l += size-1;
        else l -= 1;
        linkedList[l] = value;
        return true;
    }

    bool insertLast(int value) {
        if (len == size)
            return false;
        if (len == 0) {
            linkedList[r] = value;
            len++;
            return true;
        }
        len++;
        if (r == size - 1)
            r = 0;
        else
            r++;
        linkedList[r] = value;
        return true;
    }

    bool deleteFront() {
        if (len ==0) return false;
        len--;
        if (len == 0) {
            return true;
        }
        if (l == size - 1)
            l = 0;
        else l++;
        return true;

    }

    bool deleteLast() {
        if (len ==0) return false;
        len--;
        if (len == 0) {
            return true;
        }
        if (r == 0)
            r = size-1;
        else r--;
        return true;
    }

    int getFront() {
        
        return len==0?-1:linkedList[l];
    }

    int getRear() {
        return len == 0 ? -1 : linkedList[r];
    }

    bool isEmpty() {
        return len == 0;
    }

    bool isFull() {
        return len == size;
    }
};
